package com.fire.control.system.module.device.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.fire.control.system.dto.GroupListDTO;
import com.fire.control.system.dto.SelectDeviceGroupDTO;
import com.fire.control.system.dto.SelectGroupDTO;
import com.fire.control.system.entity.DeviceGroup;

public interface DeviceGroupMapper{
	
	/**
	 * @author: xiechengguang 
	 * @Title: getDeviceGroupList   
	 * @Description: 获取设备组列表  
	 */
	public List<GroupListDTO> getDeviceGroupList(@Param("companyId") String companyId);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getDetailById   
	 * @Description: 根据id获取设备组详细  
	 */
	public GroupListDTO getDetailById(@Param("id") String id);
	
	/**
	 * @author: xiechengguang 
	 * @Title: deleteById   
	 * @Description: 根据id删除设备组（软删除）  
	 */
	@Update("update t_device_group g set g.status = false where g.id = #{id}")
	public int deleteById(@Param("id") String id);
	
	@Select("SELECT * FROM t_device_group WHERE status = true AND id = #{id}")
	public DeviceGroup findById(String id);
	
	/**
	 * @author: xiechengguang 
	 * @Title: searchDeviceGroups   
	 * @Description: 根据设备名称模糊匹配  
	 */
	public List<GroupListDTO> searchDeviceGroups(@Param("groupName")String groupName, @Param("companyIds") List<String> companyIds);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getDeviceGroupList   
	 * @Description: 根据企业id,获取下拉选的设备组 
	 */
	@Select("select g.id,g.group_name from t_device_group g where g.company_id = #{id}")
	public List<SelectGroupDTO> getGroupsByCompanyId(String id);
	
	/**
	 * @author: xiechengguang 
	 * @Title: updateDeviceGroupInfo   
	 * @Description: 更新设备组实体  
	 */
	public void updateDeviceGroupInfo(DeviceGroup deviceGroup);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getDeviceGroups   
	 * @Description: 根据企业id获取设备组  
	 */
	@Select("select id,group_name from t_device_group g where g.company_id = #{id}")
	public List<SelectDeviceGroupDTO> getDeviceGroups(String id);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getCompanyAndCountyDeviceGroups   
	 * @Description: 企业 + 县区下的设备对应的设备组  
	 */
	@Select("select id,group_name from t_device_group g where g.status = true AND g.company_id = #{companyId} AND g.area_id = #{countyId}")
	public List<SelectDeviceGroupDTO> getCompanyAndCountyDeviceGroups(@Param("companyId") String companyId, @Param("countyId") String countyId);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getCompanyAndCountyGatewayGroups   
	 * @Description: 企业 + 县区下的设备对应的设备组  
	 */
	@Select("select id,group_name from t_device_group g where g.company_id = #{companyId} AND g.area_id = #{countyId}")
	public List<SelectDeviceGroupDTO> getCompanyAndCountyGatewayGroups(@Param("companyId") String companyId, @Param("countyId") String countyId);
	
	@Insert("insert into t_user_device_group (id,user_id,group_id,create_time,status) values (UUID(),#{userId},#{groupId},now(),true)")
	public void saveUserGroup(@Param("groupId") String groupId, @Param("userId") String userId);
	
	
	@Select("SELECT * FROM t_device_group WHERE status = true")
	public List<DeviceGroup> getAllGroups();
	
	
	/**
	 * @author: xiechengguang 
	 * @Title: getGroupsByUserId   
	 * @Description: TODO
	 */
	public List<SelectGroupDTO> getGroupsByUserId(@Param("userId") String userId);
	
	
}
